
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class zulController extends CI_Controller {
	function dateFormat($date,$onlyMonth=FALSE){
		$m		= array(1=>"Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember");
		if($onlyMonth == TRUE){
			$index	= $date + 0;
			$dateF	= $m[$index];
		} else {
			$date	= explode("-",$date);
			$index	= $date[1]+0;
			$dateF	= $date[2]." ".$m[$index]." ".$date[0];
		}
		return $dateF;
	}
	public function checkLogin()
	{	
		//untuk memastikan bahwa user telah memlakukan login
		if( $this->session->userdata('username') == FALSE && $this->session->userdata('password') == FALSE) {
			$this->session->set_flashdata('message', '<div class="error">Lakukan login terlebih dahulu</div>');
			redirect ('Login');
		}
	}
	public function checkAkses($idRole)
	{
		//$idRole akan selalu dalam bentuk array
		is_array($idRole)||$idRole=array($idRole);
		$countIdRole = count($idRole);
		$statusIdRole = FALSE;
		for($i=0; $i<$countIdRole; $i++)
		{
			if($this->session->userdata('role') == $idRole[$i])
				$statusIdRole = TRUE; 	
		}
		if ($statusIdRole == FALSE)
		{
			$this->session->set_flashdata('message', 'Anda tidak dapat mengakses halaman ini, silahkan hubungi administrator');
			redirect (base_url());
		}	
	}
	public function checkSession(){
		if($this->session->userdata("username") != NULL && $this->session->userdata("password") != NULL){
			redirect("Home");
		}
	}
}
